package com.gljx.spring.manage.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.NamedThreadLocal;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.gljx.constant.Constant;
import com.gljx.web.service.HandelServcie;
import com.gljx.web.service.SysService;
import com.sun.xml.internal.ws.util.StringUtils;

public class AddMenuTimesInterceptor extends HandlerInterceptorAdapter {

    private Logger logger = Logger.getLogger(getClass());

    @Autowired
    private SysService sysServcie;

    /**
     * 后拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        //路径
        String url = request.getRequestURI();

        //账户
        String userNumber = (String) SecurityUtils.getSubject().getPrincipal();
        if (userNumber != null && !userNumber.isEmpty() && url != null) {
            url = url.replaceAll("/DrivingSys/", "/");
            url = url.replaceAll("/DrivingSys/", "/");
            url = url.replaceAll("/DrivingSys/", "/");
            String result = sysServcie.menuMemory(url, userNumber, Constant.Project_ID);
            if (!"success".equals(result)) {
                logger.error("#记忆用户(" + userNumber + ")操作菜单#" + url + "# ORACLE异常：" + result);
            }
        }
    }
}
